package org.dragon.commons;

/**
 * Author:     Zhao Yan
 * DateTime:   2023/5/17 10:14
 */
public class JsonResult {

    public int code;

    public String message;

    public Object content;

    public JsonResult(int code, String message, Object content) {
        this.code = code;
        this.message = message;
        this.content = content;
    }

    public static JsonResult ok() {
        return ok(null);
    }

    public static JsonResult ok(Object content) {
        return new JsonResult(0, null, content);
    }

    public static JsonResult ok(String message, Object content) {
        return new JsonResult(0, message, content);
    }

    public static JsonResult fail(Object content) {
        return new JsonResult(Errors.Unknown.code, Errors.Unknown.message, content);
    }

    public static JsonResult fail(int errorCode, String message, Object content) {
        return new JsonResult(errorCode, message, content);
    }

    public static JsonResult fail(Errors error) {
        return new JsonResult(error.code, error.message, null);
    }

    public static JsonResult fail(Errors error, Object content) {
        return new JsonResult(error.code, error.message, content);
    }
}